package com.zzxy.spring1.factory;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyBeanPostProcessor implements BeanPostProcessor {

    private static final Logger logger = LoggerFactory.getLogger(MyBeanPostProcessor.class);

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        // 在bean初始化之前执行的操作
        logger.info("Before initialization of bean '{}': {}", beanName, bean.getClass().getSimpleName());
        return bean; // 返回bean实例，允许对bean进行替换（如果需要的话）
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        // 在bean初始化之后执行的操作
        logger.info("After initialization of bean '{}': {}", beanName, bean.getClass().getSimpleName());
        return bean; // 返回bean实例，允许对bean进行替换（如果需要的话）
    }
}